package com.ruoyi.web.controller.ydz;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.OldDrugSpecification;
import com.ruoyi.web.service.IOldDrugSpecificationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 旧药品规格Controller
 *
 * @author drx
 * @date 2024-03-01
 */
@Controller
@RequestMapping("/ydz/specification")
@Api(tags = "旧药品规格")
public class OldDrugSpecificationController extends BaseController
{
    private String prefix = "ydz/specification";

    @Autowired
    private IOldDrugSpecificationService oldDrugSpecificationService;

    @RequiresPermissions("ydz:specification:view")
    @GetMapping()
    public String specification()
    {
        return prefix + "/specification";
    }

    /**
     * 查询旧药品规格列表
     */
    @RequiresPermissions("ydz:specification:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询旧药品规格列表")
    public TableDataInfo list(OldDrugSpecification oldDrugSpecification)
    {
        startPage();
        List<OldDrugSpecification> list = oldDrugSpecificationService.selectOldDrugSpecificationList(oldDrugSpecification);
        return getDataTable(list);
    }

    /**
     * 导出旧药品规格列表
     */
    @RequiresPermissions("ydz:specification:export")
    @Log(title = "旧药品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出旧药品规格列表")
    public AjaxResult export(OldDrugSpecification oldDrugSpecification)
    {
        List<OldDrugSpecification> list = oldDrugSpecificationService.selectOldDrugSpecificationList(oldDrugSpecification);
        ExcelUtil<OldDrugSpecification> util = new ExcelUtil<OldDrugSpecification>(OldDrugSpecification.class);
        return util.exportExcel(list, "旧药品规格数据");
    }

    /**
     * 新增旧药品规格
     */
    @GetMapping("/add")
    @ApiOperation("新增旧药品规格")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存旧药品规格
     */
    @ApiOperation("新增保存旧药品规格")
    @RequiresPermissions("ydz:specification:add")
    @Log(title = "旧药品规格", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OldDrugSpecification oldDrugSpecification)
    {
        return toAjax(oldDrugSpecificationService.insertOldDrugSpecification(oldDrugSpecification));
    }

    /**
     * 修改旧药品规格
     */
    @ApiOperation("修改旧药品规格")
    @RequiresPermissions("ydz:specification:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OldDrugSpecification oldDrugSpecification = oldDrugSpecificationService.selectOldDrugSpecificationById(id);
        mmap.put("oldDrugSpecification", oldDrugSpecification);
        return prefix + "/edit";
    }

    /**
     * 修改保存旧药品规格
     */
    @ApiOperation("修改保存旧药品规格")
    @RequiresPermissions("ydz:specification:edit")
    @Log(title = "旧药品规格", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OldDrugSpecification oldDrugSpecification)
    {
        return toAjax(oldDrugSpecificationService.updateOldDrugSpecification(oldDrugSpecification));
    }

    /**
     * 删除旧药品规格
     */
    @ApiOperation("删除旧药品规格")
    @RequiresPermissions("ydz:specification:remove")
    @Log(title = "旧药品规格", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oldDrugSpecificationService.deleteOldDrugSpecificationByIds(ids));
    }
}
